<template>
  <div class="info" v-loading="loading">
    <div class="card_con mb15">
      <el-row>
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">关键字：</div>
          <el-input
            clearable
            v-model="keyName"
            placeholder="请输入关键字"
          ></el-input>
        </el-col>
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">状态：</div>
          <el-select v-model="judgeId" clearable placeholder="请选择">
            <el-option
              v-for="item in judgeArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="9" class="pr40">
          <div class="fz13 mb10">时间：</div>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-col>
        <el-col :span="5">
          <div class="fz13 mb10">&nbsp;</div>
          <el-button type="primary" @click="handleQuery">查询</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="card_con">
      <el-table
        border
        :data="tableData"
        :header-cell-style="{
          'text-align': 'center',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        highlight-current-row
      >
        <el-table-column prop="mchid" label="店铺id" min-width="12%">
        </el-table-column>
        <el-table-column label="用户头像" min-width="10%">
          <template slot-scope="scope">
            <div class="slt" v-if="scope.row.mch">
              <el-popover placement="right" width="200" trigger="hover">
                <img
                  class="tbImg1"
                  :src="scope.row.mch.uapply.avatar.src"
                  alt=""
                />
                <img
                  class="tbImg"
                  slot="reference"
                  :src="scope.row.mch.uapply.avatar.src"
                  alt=""
                />
              </el-popover>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="mch.uapply.phone"
          label="登录用户名"
          min-width="16%"
        >
        </el-table-column>
        <el-table-column prop="mch.type" label="店铺类型" min-width="10%">
        </el-table-column>
        <el-table-column label="状态" min-width="20%">
          <template slot-scope="scope">
            <div v-if="scope.row.extend">
              <div v-if="scope.row.extend.alipay">
                支付宝： {{ scope.row.extend.alipay.status }}
              </div>
              <div v-if="scope.row.extend.wxpay">
                <div>微信： {{ scope.row.extend.wxpay.status }}</div>
              </div>
            </div>
            <div v-if="scope.row.extend.length === 0">暂未提交</div>
          </template>
        </el-table-column>
        <el-table-column label="申请单编号" min-width="20%">
          <template slot-scope="scope">
            <div v-if="scope.row.extend">
              <div v-if="scope.row.extend.wxpay">
                <div v-if="scope.row.extend.wxpay.sub_oid">
                  微信：{{ scope.row.extend.wxpay.sub_oid }}
                </div>
                <div v-else>微信：暂无</div>
              </div>
              <div v-if="scope.row.extend.alipay">
                <div v-if="scope.row.extend.alipay.sub_oid">
                  支付宝：{{ scope.row.extend.alipay.sub_oid }}
                </div>
                <div v-else>支付宝：暂无</div>
              </div>
            </div>
            <div v-if="scope.row.extend.length === 0">暂无</div>
          </template>
        </el-table-column>
        <el-table-column label="提交时间" min-width="20%">
          <template slot-scope="scope">
            <div v-if="scope.row.extend">
              <div v-if="scope.row.extend.alipay">
                支付宝： {{ scope.row.extend.alipay.time1 }}
              </div>
              <div v-if="scope.row.extend.wxpay">
                微信： {{ scope.row.extend.wxpay.time1 }}
              </div>
            </div>
            <div v-if="scope.row.extend.length === 0">暂未提交</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="15%">
          <template slot-scope="scope">
            <div class="caozuo">
              <div
                class="handleExamine hand_cs"
                @click="handleDetail(scope.row)"
              >
                详情
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <Pagination :page="page" @onCurrentChange="handleCurrentChange" />
      </div>
      <el-dialog
        class="detailDialog"
        title="详情"
        :visible.sync="detailDialog"
        width="70%"
        @close="close"
      >
        <DetailDialog v-if="detailDialog" :rowData="rowData"></DetailDialog>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import DetailDialog from "./setting_in_detail.vue";
import Pagination from "@/components/Pagination.vue";
import { settleInList } from "@/api/merchant";
export default {
  components: { Pagination, DetailDialog },
  data() {
    return {
      time: "",
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      keyName: "", //关键字搜索
      loading: true,
      judgeId: "",
      judgeArr: [
        //已驳回、进行中、待提交、已关闭、待审核、已完成
        { id: "待签约", name: "待签约" },
        { id: "已驳回", name: "已驳回" },
        { id: "进行中", name: "进行中" },
        { id: "待提交", name: "待提交" },
        { id: "已关闭", name: "已关闭" },
        { id: "待审核", name: "待审核" },
        { id: "已完成", name: "已完成" },
      ],
      tableData: [],
      detailDialog: false,
      rowoid: "",
      rowData: {},
    };
  },
  methods: {
    async settleInList() {
      const { data, err } = await settleInList({
        page: this.page.pageNum,
        st: this.time ? this.time[0] : 0,
        se: this.time ? this.time[1] : 0,
        status: this.judgeId,
        key: this.keyName,
      });
      if (err === 0) {
        this.loading = false;
        this.tableData = data.data;
        this.page.pageSize = data.per_page;
        this.page.total = data.total;
      }
    },
    //详情
    handleDetail(row) {
      this.detailDialog = true;
      console.log(row);
      this.rowData = row;
    },

    //查询
    handleQuery() {
      this.loading = true;
      this.page.pageNum = 1;
      this.settleInList();
    },
    // 当前页: ${val}
    handleCurrentChange(val) {
      this.loading = true;
      this.page.pageNum = val;
      this.settleInList();
    },
    close() {
      this.detailDialog = false;
    },
  },
  created() {
    this.settleInList();
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/index.scss";
.handleExamine {
  margin-left: 20px;
}
.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
.el-select {
  width: 100%;
}

.tb {
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
}
.row {
  display: flex;
  border-radius: 2px;
  .l {
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    font-size: 13px;
    i {
      margin-right: 6px;
      font-size: 13px;
    }
    &:hover {
      cursor: pointer;
    }
  }
  .l:nth-child(3) {
    border-right: 0;
  }
}
.caozuo {
  display: flex;
  justify-content: center;
  .handleDelete {
    margin-left: 20px;
  }
}
.detailDialog {
  /deep/.el-dialog {
    height: 82%;
    margin-top: 10vh !important;
    .el-dialog__body {
      height: 80%;
      overflow: auto;
    }
  }
}
.handleEdit {
  margin-left: 20px;
}
</style>
